"use strict";
// pages/product/info.js
var common = require('../../../utils/api.js')
var api = common.api
var util = require('../../../utils/util.js')
Page({
  data:{
    product:{},
    title:'项目详情',
    productstatus:util.productstatus,
    statusselect:'',
    pid:''
  },
  onShow:function(options){
    
  },
  onReady:function(){
    // 页面渲染完成
  },
  onLoad:function(options){
    // 页面显示
    util.showLoading({title: '加载中'})
    var that = this
    this.data.pid = options.pid
    // 页面初始化 options为页面跳转所带来的参数
    api.getProductInfo(options.pid,function(result){
      console.log('getProductInfo',result,that.productstatus,that.headTitle)
      //更新数据
      that.mapData(result)
      that.setData({product:result})
      util.hideLoading()
    })
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  mapData:function(result){
    result.manager = util.getSelectmanage(result.manager)
    result.teamleader = util.getSelectteamleaderslistJoin(result.teamleader)
    result.statusselect=util.productstatus[result.status-1].name
  },
  bindStatuslistChange:function(e){
    var index = e.detail.value
    var name = this.data.productstatus[index].name
    var status = this.data.productstatus[index].status
    console.log("状态",name,index)
    this.setData({
      statusselect: name
    })
    api.setProductInfo(this.id,status,function(result){
      if(result.success==1){
        wx.showToast({
            title: '修改状态成功',
            icon: 'success',
            duration: 2000
        })
      }
    })
  }
})